(function($) {
$(document).ready(function() {
	var validator = $("#add_form").validate({
		rules: {
			'orders[type]': {
				required: true,
				number: true
			},
            'orders[username]': "required",
			'orders[user_id]': {
				required: true,
				number: true
			}
		},
		messages: {
			'orders[type]': {
				required: "Enter type",
				number: "Enter valid number"
			},
            'orders[username]': "Enter user name",
			'orders[user_id]': {
				required: "Enter user id",
				number: "Enter valid number"
			}
		},

		errorPlacement: function(error, element) {
			if ( element.is(":radio") )
				error.appendTo( element.parent().next().next() );
			else if ( element.is(":checkbox") )
				error.appendTo ( element.next() );
			else
				error.appendTo( element.parent().next() );
		},

		submitHandler: function() {
			
			form.submit();
		},
                
		success: function(label) {
			// set &nbsp; as text for IE
			label.html("&nbsp;").addClass("checked");
		}
	});
});

})(jQuery);
